package com.boruan.qq.zxgylibrary.ui.activities;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.boruan.qq.zxgylibrary.R;
import com.boruan.qq.zxgylibrary.R2;
import com.boruan.qq.zxgylibrary.base.BaseActivity;
import com.boruan.qq.zxgylibrary.utils.KeyboardUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by 崔琦 on 2019/8/16.
 * des: 订单备注页面
 */

public class OrderRemarkActivity extends BaseActivity {
    @BindView(R2.id.edt_input_remark)
    EditText edtInputRemark;
    @BindView(R2.id.tv_input_num)
    TextView tvInputNum;

    @Override
    protected int getLayoutId() {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        return R.layout.drug_activity_order_remark;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        edtInputRemark.addTextChangedListener(new TextWatcher() {
            CharSequence input;
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                input = charSequence;
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                tvInputNum.setText(input.length() + "/50个字");
                if (input.length() > 50){
                    Toast.makeText(OrderRemarkActivity.this, "最多输入50个字！", Toast.LENGTH_SHORT).show();
                    edtInputRemark.setText(input.toString().substring(0,50));
                    edtInputRemark.setSelection(50);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }

    @OnClick({R2.id.tv_close_shop, R2.id.done_remark})
    public void onViewClicked(View view) {
        int i = view.getId();
        if (i == R.id.tv_close_shop) {
            finish();

        } else if (i == R.id.done_remark) {
            KeyboardUtils.toggleSoftInput(edtInputRemark);
            String strRemark = edtInputRemark.getText().toString().trim();
            Intent intent = new Intent();
            intent.putExtra("remark", strRemark);
            setResult(14, intent);
            finish();

        }
    }
}
